package eva.savant.business.ventas.view

import eva.savant.businessobject.vt.Cliente
import groovy.time.TimeCategory

import javax.faces.bean.ManagedBean
import javax.faces.bean.SessionScoped
import javax.annotation.PostConstruct

@SessionScoped
@ManagedBean(name = 'IIVisitaCliente')
public class IIVisitaCliente extends Bean {

  def dia= ['D','L','M','X','J','V','S']

  Date date

  @PostConstruct
  public void cleanEntity() {

    lsEntity= new ArrayList()

    date= new Date()
  }

  public List findLsEntity() {

    lsEntity= new ArrayList()

    def i= date.toCalendar().get(Calendar.DAY_OF_WEEK) - 1

    def ls= find(Cliente,'visita like ?','%'+dia[i]+'%')

    ls.each{x-> def d=TimeCategory.minus(toStartDay(date),toStartDay(x.venta)).days; lsEntity.add([x,d,d-x.frecuencia])}

    return lsEntity
  }

}
